$(function () {
    $("#jqGrid").jqGrid({
        url: 'eform/eformtemplate/list',
        datatype: "json",
        colModel: [
            { label: '模板主键', name: 'templateId', width: 60, key: true },
			{ label: '模板代码', name: 'templateCode', width: 60 },
			{ label: '模板名称', name: 'templateName', width: 90 },
			{ label: '模板配置', name: 'templateConfig', width: 200 },
            { label: '状态', name: 'status', width: 40 },
			{ label: '创建时间', name: 'createTime', width: 100 }
        ],
		viewrecords: true,
        height: 450,
        rowNum: 10,
		rowList : [10,15,30,50,100,200],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#templatesapp',
	data:{
		q:{
            keywords: null
		}
	},
	methods: {
        //查询
		query: function () {
            console.log('query');
			$("#jqGrid").jqGrid('setGridParam',{ 
                postData:{'keywords': vm.q.keywords},
                page:1 
            }).trigger("reloadGrid");
		},
        //新增
        add: function() {
            location.href = "template_add.html";
        },
        //修改
        edit: function() {
          let templateId = getSelectedRow();
          if (templateId == null) {
              return;
          }
          location.href = "template_edit.html?templateId=" + templateId;
        },
        //设计
        design: function() {
            let templateId = getSelectedRow();
            if (templateId == null) {
                return;
            }
            console.log('design', templateId)
            window.parent.location.href = "VFormDesigner.html?templateId=" + templateId;
        },
        //拟用
        preview: function() {
            let templateId = getSelectedRow();
            if (templateId == null) {
               return;
            }
            console.log('preview', templateId)
            window.open('template_preview.html?templateId=' + templateId, "_blank");
        },
        //删除
        deleteTemplates: function() {
            let templateIds = getSelectedRows();
            if(templateIds == null){
                return ;
            }
            //location.href = "/eform/eformtemplate/delete?templateIds=" + templateIds.join();
            console.log('deleteTemplates', templateIds)
		}
	}
});

